#!/usr/bin/python


print("Content-type: text/html\n\n")

import cgi, tasks

f = open("tasks.dat", "r")

t = tasks.Task("Dummy")
t = t.fromArray(eval(f.read()))

f.close()

args = cgi.FieldStorage()

if "id" in args:
    num = args["id"].value
    if "name" in args:
        name = args["name"].value
    else:
        name = "New"
    
    r = t.findTask(num[:num.index("-")])
    r.addChild(tasks.Task(name))
    f = open("tasks.dat", "w")
    f.write(str(t.toArray()))
    f.close()


